import tensorflow as tf

state = tf.Variable(0,name='counter')
print(state.name)
print(state.value())

one = tf.constant(1)

new_value = tf.add(state,one)
update = tf.assign(state,new_value)

# 变量需要初始化
init = tf.initialize_all_variables()  # must have if define variable

with tf.Session() as sess:
    sess.run(init)
    for i in range(3):
        sess.run(update)
        print(state)
        print(sess.run(state))  # 不能直接打印state的值   一定要把 sess 的指针指向 state 再进行 print 才能得到想要的结果
